load dataset and start making plots
data(rest_inspec)
ri <-
rest_inspec |>
mutate(
score = suppressWarnings(as.numeric(score)),
long = as.numeric(longitude),
lat = as.numeric(latitude)
) |>
# ✅ rename cuisine_description to cuisine here
rename(cuisine = cuisine_description) |>
select(
camis, dba, boro, cuisine, grade, score, lat, long, inspection_date
) |>
filter(
!is.na(score),
!is.na(long), !is.na(lat),
long < -70, long > -75, # keep within NYC bounds
lat > 40, lat < 41,
boro == "Manhattan",
score >= 0, score <= 40
)
# ✅ now this will work
top_cuisines <- ri |>
count(cuisine, sort = TRUE) |>
slice_head(n = 12) |>
pull(cuisine)
ri_small <- ri |> filter(cuisine %in% top_cuisines)
Plotly scatterplot: Scatterplot of restaurant locations and inspection scores
ri_small |>
mutate(text_label = str_c(
dba, " — ", cuisine,
"\nScore: ", score,
ifelse(!is.na(grade), str_c(" (Grade ", grade, ")"), ""),
"\nBorough: ", boro
)) |>
plot_ly(
x = ~long, y = ~lat, type = "scatter", mode = "markers",
color = ~score, colors = "viridis",
text = ~text_label, alpha = 0.6
) |>
layout(xaxis = list(title = "longitude"),
yaxis = list(title = "latitude"))